package com.sword.ehcache.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger配置类
 * @author sword
 * @date 2020-07-07 11:13:57
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    /**
     * 返回swaggerAPI文档
     * @return springfox.documentation.spring.web.plugins.Docket
     * @author sword
     * @date 2020-07-07 11:13:57
     */
    @Bean
    public Docket swaggerApi() {
        return new Docket(DocumentationType.OAS_30)
                // 设置该API基本信息
                .apiInfo(apiInfo())
                .select() // 返回一个ApiSelectorBuilder实例用来设置哪些接口暴露给Swagger来展现
                // 暴露@Api注解注释的所有类的方法
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 返回一个API基本信息
     * @return springfox.documentation.service.ApiInfo
     * @author sword
     * @date 2020-07-07 11:13:57
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 标题
                .title("API文档标题")
                // 描述
                .description("API文档描述")
                // 服务条款地址
                .termsOfServiceUrl("http://localhost:8080/demo")
                // 设置联系人名称、网址、电子邮件
                .contact(new Contact("sword", "http://localhost:8080/demo" , "******@163.com"))
                // 文档的版本
                .version("1.0")
                .build();
    }
}